home *** CD-ROM | disk | FTP | other *** search
/ PC Advisor 2010 April / PCA177.iso / ESSENTIALS / Firefox Setup.exe / nonlocalized / chrome / browser.jar / content / browser / places / history-panel.js < prev    next >
Encoding:
JavaScript  |  2009-07-15  |  3.2 KB  |  107 lines

  1. //@line 40 "e:\builds\moz2_slave\win32_build\build\browser\components\places\content\history-panel.js"
  2.  
  3. var gHistoryTree;
  4. var gSearchBox;
  5. var gHistoryGrouping = "";
  6. var gSearching = false;
  7.  
  8. function HistorySidebarInit()
  9. {
  10.   gHistoryTree = document.getElementById("historyTree");
  11.   gSearchBox = document.getElementById("search-box");
  12.  
  13.   gHistoryGrouping = document.getElementById("viewButton").
  14.                               getAttribute("selectedsort");
  15.  
  16.   if (gHistoryGrouping == "site")
  17.     document.getElementById("bysite").setAttribute("checked", "true");
  18.   else if (gHistoryGrouping == "visited") 
  19.     document.getElementById("byvisited").setAttribute("checked", "true");
  20.   else if (gHistoryGrouping == "lastvisited")
  21.     document.getElementById("bylastvisited").setAttribute("checked", "true");
  22.   else if (gHistoryGrouping == "dayandsite")
  23.     document.getElementById("bydayandsite").setAttribute("checked", "true");
  24.   else
  25.     document.getElementById("byday").setAttribute("checked", "true");
  26.  
  27.   initContextMenu();
  28.   
  29.   searchHistory("");
  30. }
  31.  
  32. function initContextMenu() {
  33.   // Insert "Bookmark This Link" right before the copy item
  34.   document.getElementById("placesContext")
  35.           .insertBefore(document.getElementById("addBookmarkContextItem"),
  36.                         document.getElementById("placesContext_copy"));
  37. }
  38.  
  39. function GroupBy(groupingType)
  40. {
  41.   gHistoryGrouping = groupingType;
  42.   searchHistory(gSearchBox.value);
  43. }
  44.  
  45. function historyAddBookmarks()
  46.   // no need to check gHistoryTree.view.selection.count
  47.   // node will be null if there is a multiple selection 
  48.   // or if the selected item is not a URI node
  49.   var node = gHistoryTree.selectedNode;
  50.   if (node && PlacesUtils.nodeIsURI(node))
  51.     PlacesUIUtils.showMinimalAddBookmarkUI(PlacesUtils._uri(node.uri), node.title);
  52. }
  53.  
  54. function searchHistory(aInput)
  55. {
  56.   var query = PlacesUtils.history.getNewQuery();
  57.   var options = PlacesUtils.history.getNewQueryOptions();
  58.  
  59.   const NHQO = Ci.nsINavHistoryQueryOptions;
  60.   var sortingMode;
  61.   var resultType;
  62.  
  63.   switch (gHistoryGrouping) {
  64.     case "visited":
  65.       resultType = NHQO.RESULTS_AS_URI;
  66.       sortingMode = NHQO.SORT_BY_VISITCOUNT_DESCENDING;
  67.       break; 
  68.     case "lastvisited":
  69.       resultType = NHQO.RESULTS_AS_URI;
  70.       sortingMode = NHQO.SORT_BY_DATE_DESCENDING;
  71.       break; 
  72.     case "dayandsite":
  73.       resultType = NHQO.RESULTS_AS_DATE_SITE_QUERY;
  74.       break;
  75.     case "site":
  76.       resultType = NHQO.RESULTS_AS_SITE_QUERY;
  77.       sortingMode = NHQO.SORT_BY_TITLE_ASCENDING;
  78.       break;
  79.     case "day":
  80.     default:
  81.       resultType = NHQO.RESULTS_AS_DATE_QUERY;
  82.       break;
  83.   }
  84.  
  85.   if (aInput) {
  86.     query.searchTerms = aInput;
  87.     if (gHistoryGrouping != "visited" && gHistoryGrouping != "lastvisited") {
  88.       sortingMode = NHQO.SORT_BY_TITLE_ASCENDING;
  89.       resultType = NHQO.RESULTS_AS_URI;
  90.     }
  91.   }
  92.  
  93.   options.sortingMode = sortingMode;
  94.   options.resultType = resultType;
  95.  
  96.   // call load() on the tree manually
  97.   // instead of setting the place attribute in history-panel.xul
  98.   // otherwise, we will end up calling load() twice
  99.   gHistoryTree.load([query], options);
  100. }
  101.  
  102. window.addEventListener("SidebarFocused",
  103.                         function()
  104.                           gSearchBox.focus(),
  105.                         false);
  106.